package com.bidianying.config;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisShardInfo;
import redis.clients.jedis.ShardedJedisPool;


@Component
public class BeanConfig {
	
	@Bean
	public RestTemplate restTemplate(){
		return new RestTemplate();
	}
	
	@Bean
	public ShardedJedisPool shardedJedisPool(){
		List<JedisShardInfo> list = new ArrayList<JedisShardInfo>();
		list.add(jedisShardInfo());
		ShardedJedisPool shardedJedisPool = new ShardedJedisPool(jedisPoolConfig(),list);
		return shardedJedisPool;
	}
	
	
	private JedisShardInfo jedisShardInfo(){
		JedisShardInfo jedisShardInfo = new JedisShardInfo("120.24.249.102",6379);
		jedisShardInfo.setPassword("w516511915redis");
		return jedisShardInfo;
	}
	
	private JedisPoolConfig jedisPoolConfig(){
		JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
		jedisPoolConfig.setMaxWaitMillis(1000);
		jedisPoolConfig.setTestOnBorrow(true);
		jedisPoolConfig.setMaxIdle(10);
		return jedisPoolConfig;
	}
}
